package jfox.platform.logging.bo;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import jfox.platform.common.PaginationList;
import jfox.platform.common.Utils;
import jfox.platform.infrastructure.DataAccessObject;
import jfox.platform.infrastructure.SuperBO;
import jfox.platform.logging.dao.LogDAO;
import jfox.platform.logging.entity.Log;

/**
 * @author <a href="mailto:yang_y@sysnet.com.cn">Young Yang</a>
 */
@Stateless
@Local
public class LogBOBean extends SuperBO implements LogBO{

    @EJB
    LogDAO logDAO;

    public DataAccessObject getDataAccessObject() {
        return logDAO;
    }

    public void log(Log log) {
        logDAO.insertLog(log);
    }

    public void deleteLog(long id){
        logDAO.deleteLog(id);
    }

    public void deleteLogs(long[] ids){
        for(long id : ids){
            logDAO.deleteLog(id);
        }
    }

    public PaginationList<Log> searchLog(String username, long moduleId, String type, long startTime, long endTime, int start, int limit) {
        if(startTime == 0) {
            startTime = Utils.getTodayLong() * 1000000;
        }
        if(endTime == 0){
            endTime = Utils.getTomorrowLong() * 1000000;
        }
        return logDAO.searchLog(username,moduleId,type,startTime,endTime, start, limit);
    }

}
